package cn.hackcloud.javabase.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class TestCallabe {
	public static void main(String[] args) throws Exception {
		ThreadDemo demo = new ThreadDemo();
		FutureTask<Integer> futureTask = new FutureTask<>(demo);
		Thread thread = new Thread(futureTask);
		thread.start();
		Integer result = futureTask.get();
		ExecutorService service = Executors.newSingleThreadExecutor();
		FutureTask<Integer> task = new FutureTask<>(new Callable<Integer>() {

			@Override
			public Integer call() throws Exception {
				Integer sum = 0;
				for (int j = 0; j <= 100; j++) {
					sum += j;
				}
				return sum;
			}
		});
		service.execute(task);
		System.err.println(task.get());

	}

}

class ThreadDemo implements Callable<Integer> {

	@Override
	public Integer call() throws Exception {
		Integer sum = 0;
		for (int j = 0; j <= 100; j++) {
			sum += j;
		}
		return sum;
	}

}
